#include <QDebug>

#include "tukupageparser.h"

namespace Jcr
{
class TukuPageParserPrivate
{
public:
    QUrl imageUrl;
};

TukuPageParser::TukuPageParser(QObject* parent) : ModelPageParser(parent)
{
    d_ptr = new TukuPageParserPrivate;
}

TukuPageParser::~TukuPageParser()
{
    delete d_ptr;
}

void TukuPageParser::processNode(GumboNode *node)
{
    if (node->v.element.tag == GUMBO_TAG_A) {
        GumboAttribute* attr = gumbo_get_attribute(&node->v.element.attributes, "href");
        if (attr) {
            qDebug() << "image url: " << attr->value;
            d_ptr->imageUrl = QUrl(attr->value);
        }
    }
}

void TukuPageParser::finalize()
{
    if (!d_ptr->imageUrl.isEmpty())
        emit getImageUrl(d_ptr->imageUrl);
}

} // namespace jcr
